<template>
  <div id="app">
    <!--路由v-if修改为v--show-->
    <router-view v-if="isLoad" />
    <!--    <router-view v-show="isLoad" />-->
  </div>
</template>

<script>
import { updateDocumentTitle } from '@/utils/document-title-util';
import { getPk, getSalt } from "./api/sign";

export default {
  name: 'App',
  provide () {
    return {
      reload: this.reload
    }
  },
  data () {
    return {
      isLoad: true,
    }
  },
  created () {
    this.initPk()
    // 恢复主题
    this.$store.dispatch('theme/recoverTheme');
  },
  methods: {
    reload () {
      console.log("进入强制刷新=============", this.isLoad)
      this.isLoad = false
      this.$nextTick(function () {
        console.log('111111111', this.isLoad)
        this.isLoad = true
        console.log('2222222', this.isLoad)
      });
      /*setTimeout(()=>{
        this.isLoad=true
      },20)*/
    },
    /* 路由切换更新浏览器标题 */
    setDocumentTitle () {
      updateDocumentTitle(
        this.$route,
        (key) => this.$t(key),
        this.$store.state.theme.tabs
      );
    },
    /**
     * 初始化安全
     * @returns {Promise<void>}
     */
    async initPk () {
      let salt = await getSalt()
      this.$store.commit('signature/setSalt', salt)
      let pk = await getPk();
      this.$store.commit('signature/setPk', pk)
      this.isLoad = true
    }
  },
  watch: {
    '$i18n.locale' () {
      this.setDocumentTitle();
    },
    $route () {
      this.setDocumentTitle();
    }
  }
};
</script>
<style>
@import url('/src/styles/iconfont.css');
</style>
